﻿using Customer.Domain;
using Customer.Read.API.Applcation.Command.CusContactCommand;
using Customer.Read.API.Dtos;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Customer.Read.API.Controllers
{
    /// <summary>
    /// 客户联系人控制器（读）
    /// </summary>
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class CusContactReadController : ControllerBase
    {
        private readonly IMediator _mediator;

        public CusContactReadController(IMediator mediator)
        {
            this._mediator = mediator;
        }

        /// <summary>
        /// 显示客户联系人信息
        /// </summary>
        /// <returns>返回满足条件的数据</returns>
        [HttpGet]
        public async Task<ApiResult<List<CusContact>>> GetCusContact()
        {
            ApiResult<List<CusContact>> result = new ApiResult<List<CusContact>>();
            try
            {
                result.Data = await _mediator.Send(new SelectCusContactCommand());
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填客户联系人信息
        /// </summary>
        /// <param name="command">要反填的实体id</param>
        /// <returns>返回满足条件的数据</returns>
        [HttpGet]
        public async Task<ApiResult<CusContact>> GetCusContactById([FromQuery] FantCusContactCommand command)
        {
            ApiResult<CusContact> result = new ApiResult<CusContact>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ee)
            {
                result.Code = -1;
                result.Message = ee.Message;
                throw;
            }
            return result;
        }
    }
}
